/**
 * 
 */
package org.vsg.stock.core.kline;

import java.util.Date;

import org.vsg.stock.core.KLineStock.Attribute;


/**
 * @author Bill Vison
 *
 */
public class SimpleDailyKLineStock implements DailyKLineStock {
	
	private Date date;

	private double open;

	private double high;

	private double low;
	
	private double close;

	private double yieldRate;
	
	private long vol;

	private double transactionValue;	
	

	/**
	 * @return 
	 */
	public double getYieldRate() {
		return yieldRate;
	}

	/**
	 * @param yieldRate
	 */
	public void setYieldRate(double yieldRate) {
		this.yieldRate = yieldRate;
	}

	/**
	 * @param date
	 */
	public void setDate(Date date) {
		this.date = date;
	}

	/**
	 * @param open
	 */
	public void setOpen(double open) {
		this.open = open;
	}

	/**
	 * @param high
	 */
	public void setHigh(double high) {
		this.high = high;
	}

	/**
	 * @param low
	 */
	public void setLow(double low) {
		this.low = low;
	}

	/**
	 * @param close
	 */
	public void setClose(double close) {
		this.close = close;
	}

	/**
	 * @param vol
	 */
	public void setVol(long vol) {
		this.vol = vol;
	}

	/**
	 * @param transactionValue
	 */
	public void setTransactionValue(double transactionValue) {
		this.transactionValue = transactionValue;
	}

	/**
	 * @return 
	 */
	@Override
	public Date getDate() {
		// TODO Auto-generated method stub
		return date;
	}

	/* (non-Javadoc)
	 * @see org.vsg.stock.core.KLineStock#getOpen()
	 */
	/**
	 * @return 
	 */
	@Override
	public double getOpen() {
		// TODO Auto-generated method stub
		return open;
	}

	/* (non-Javadoc)
	 * @see org.vsg.stock.core.KLineStock#getHigh()
	 */
	/**
	 * @return 
	 */
	@Override
	public double getHigh() {
		// TODO Auto-generated method stub
		return high;
	}
	
	/* (non-Javadoc)
	 * @see org.vsg.stock.core.KLineStock#getLow()
	 */
	/**
	 * @return 
	 */
	@Override
	public double getLow() {
		// TODO Auto-generated method stub
		return low;
	}

	/* (non-Javadoc)
	 * @see org.vsg.stock.core.KLineStock#getClose()
	 */
	/**
	 * @return 
	 */
	@Override
	public double getClose() {
		// TODO Auto-generated method stub
		return close;
	}

	/* (non-Javadoc)
	 * @see org.vsg.stock.core.KLineStock#getVol()
	 */
	/**
	 * @return 
	 */
	@Override
	public long getVol() {
		// TODO Auto-generated method stub
		return vol;
	}

	/* (non-Javadoc)
	 * @see org.vsg.stock.core.KLineStock#getTransactionValue()
	 */
	/**
	 * @return 
	 */
	@Override
	public double getTransactionValue() {
		// TODO Auto-generated method stub
		return transactionValue;
	}

	/* (non-Javadoc)
	 * @see org.vsg.stock.core.KLineStock#getAverage()
	 */
	/**
	 * @return 
	 */
	@Override
	public double getAverage() {
		// TODO Auto-generated method stub
		return (open+close) / 2;
	}

	@Override
	public double getBottom() {
		// TODO Auto-generated method stub
		return this.open > this.close ? this.close : this.open;
	}


	@Override
	public double getTop() {
		// TODO Auto-generated method stub
		return this.open > this.close ? this.open : this.close;
	}

	@Override
	public Attribute[] sortAttrs() {
		// TODO Auto-generated method stub
		
		double bottom = this.open > this.close ? this.close : this.open;
		
		Attribute[] attrs = new Attribute[4];
		attrs[0] = Attribute.LOW;
		
		if ( bottom == this.open ) {
			attrs[1] = Attribute.OPEN;
			attrs[2] = Attribute.CLOSE;
		} else {
			attrs[1] = Attribute.CLOSE;
			attrs[2] = Attribute.OPEN;
		}
		attrs[3] = Attribute.HIGH;
		
		return attrs;
	}
	
	
	/**
	 * @return 
	 */
	@Override
	public String toString() {
		return "SimpleDailyKLineStock [close=" + close + ", date=" + date
				+ ", high=" + high + ", low=" + low + ", open=" + open
				+ ", transactionValue=" + transactionValue + ", vol=" + vol
				+ ", yieldRate=" + yieldRate + "]";
	}

	
	
}
